package com.zipking.cloud.springbootmybatis.kafka;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Service
public class TransformFactory {


    @Autowired
    private Map<String, TransformMetaData> map;


    /**
     * 根据媒体名称获取转换后的对象
     *
     * @return
     */
    public   Material getMaterial(KafkaData source) {
        if (source == null || source.getMediaName() == null) {
            log.error("source为空或source中不包含素材来源,data=[{}]", source);
            return null;
        }
        MediaEnum mediaSource = MediaEnum.create(source.getMediaName());
        TransformMetaData transformMetaData = map.get(mediaSource.getAlias());
        if (transformMetaData == null) {
            log.error("无法解析的素材来源:data=[{}]", source.getMediaName());
            return null;
        }
        return transformMetaData.getMaterial(source);
    }
}
